package 二叉搜索树的最小绝对差;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 二叉搜索树的最小绝对差
 * @date 2022/11/6 16:15
 */
public class Demo530 {
    TreeNode pre=null;
    int min=Integer.MAX_VALUE;
    public int getMinimumDifference(TreeNode root) {
        if(root==null){
            return 0;
        }
        //左
        getMinimumDifference(root.left);
        if(pre!=null){
             min=Math.min(min,Math.abs(root.val- pre.val));
        }
        pre=root;
        getMinimumDifference(root.right);
        return min;
    }
    //Definition for a binary tree node.
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) {
            this.val = val;}
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
